www.mxdraw.com
|
构造选择集
[helpstring("method Select2")] HRESULT Select2([in] MCAD_McSelect Mode, [in] VARIANT point1, [in] VARIANT point2, [in,optional] VARIANT filterType, [in,optional] VARIANT filterData);
参数 |
说明 |
[in] MCAD_McSelect Mode |
构造选择集方式 |
[in] VARIANT point1 |
构造择择集时需要使用到的点对象 |
[in] VARIANT point2 |
构造择择集时需要使用到的点对象 |
[in,optional] VARIANT filterType |
构造选择集的过滤数据的类型 |
[in,optional] VARIANT filterData |
构造选择集的过滤数据 |
例如: C# ,得到0层,上的直线和圆弧,并且颜色是红色的实体。
private void button14_Click_1(object sender, EventArgs e) { MxDrawSelectionSet ss = new MxDrawSelectionSet(); MxDrawResbuf filter = new MxDrawResbuf(); // "0",是图层名,8是DXF码,代表"0"是个图层字符串。 // 选择 0层上的实体。 filter.AddString("0", 8); // 选择直线或圆弧实体。5020是DXF码,代表"LINE"是类型字符串。 filter.AddString("LINE,ARC", 5020); // 选择红色的实体。1为颜色索引值,代表红色。 62是DXF码,但1是个颜色类型。 filter.AddLong(1,62); ss.Select2(MCAD_McSelect.mcSelectionSetAll, null, null, null,filter); int i = 0; for (; i < ss.Count; i++) { MxDrawEntity ent = ss.Item(i); MessageBox.Show(ent.Dxf0); } }
例如: VC6代码
void CTestOcxForVc6Dlg::OnDelplButton() { // TODO: Add your control notification handler code here MxDrawXLib::IMxDrawSelectionSetPtr ssGet; ssGet.CreateInstance(__uuidof( MxDrawXLib::MxDrawSelectionSet )); if(ssGet == NULL) { return; } MxDrawXLib::IMxDrawResbufPtr filter; filter.CreateInstance(__uuidof( MxDrawXLib::MxDrawResbuf )); // 设置多义线为过滤条件 filter->AddString(_T("*POLYLINE"),5020); std::auto_ptr<_variant_t> spVarPt1(new _variant_t); std::auto_ptr<_variant_t> spVarPt2(new _variant_t); ssGet->Select2(mcSelectionSetAll,*spVarPt1.get(),*spVarPt2.get(),NULL,filter); for(long i = 0; i < ssGet->GetCount();i++) { MxDrawXLib::IMxDrawEntityPtr spEnt = ssGet->Item(i); if(spEnt == NULL) continue; spEnt->Erase(); } }
例如: VC代码,得到选择的图块个数.
using namespace MxDrawXLib; void CTestDynCreateDlg::DoSelectBlk() { IMxDrawUtilityPtr utility; utility.CreateInstance(__uuidof( MxDrawUtility )); if(utility == NULL) { return; } _variant_t varPrompt; V_VT(&varPrompt) = VT_BSTR; CString sPrompt; sPrompt.Format(_T("选择一个实体:")); V_BSTR(&varPrompt) = sPrompt.AllocSysString(); _variant_t varSelPt; MxDrawXLib::IMxDrawEntityPtr spEnt = utility->GetEntity(&varSelPt,varPrompt); if(spEnt == NULL) return; CString sName((const char*)(spEnt->ObjectName) ); CComPtr<IMxDrawBlockReference> spBlk; spEnt->QueryInterface(&spBlk); if(spBlk == NULL) { return; } CString sBlkName = spBlk->GetBlockName(); MxDrawXLib::IMxDrawSelectionSetPtr ssGet; ssGet.CreateInstance(__uuidof( MxDrawXLib::MxDrawSelectionSet )); if(ssGet == NULL) { return; } MxDrawXLib::IMxDrawResbufPtr filter; filter.CreateInstance(__uuidof( MxDrawXLib::MxDrawResbuf )); // 设置图块 filter->AddString(_T("INSERT"),5020); _bstr_t blkName((LPCTSTR)sBlkName); filter->AddString(blkName,2); std::auto_ptr<_variant_t> spVarPt1(new _variant_t); std::auto_ptr<_variant_t> spVarPt2(new _variant_t); ssGet->Select2(mcSelectionSetAll,*spVarPt1.get(),*spVarPt2.get(),NULL,filter); if(ssGet->GetCount() == 0) return; // for(long i = 0; i < ssGet->GetCount();i++) // { // MxDrawXLib::IMxDrawEntityPtr spEnt = ssGet->Item(i); // if(spEnt == NULL) // continue; // } CString sT; sT.Format(_T("发现了%d个"), ssGet->GetCount()); AfxMessageBox(sT); }